package com.ruoyi.crm.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.Mongolog;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.crm.domain.Clue;
import com.ruoyi.crm.domain.vo.BusinessTrackVo;
import com.ruoyi.crm.domain.vo.ClueTrackVo;
import com.ruoyi.crm.domain.vo.ContractVo;
import com.ruoyi.crm.service.IBusinessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/crm/business/track")
public class BusinessTrackController extends BaseController {
    @Autowired
    private IBusinessService businessService;


    @Mongolog(tableName = Mongolog.TableName.BUSINESS,title = "商机跟踪记录",businessType = BusinessType.INSERT)
//    @Log(title = "商机跟踪记录",businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusinessTrackVo vo){
        vo.setStatus(Clue.Status.TRACKING.getValue());
        return toAjax(businessService.updateBusiness(vo));

    }

    //踢回公海
//    @Log(title = "商机跟踪记录",businessType = BusinessType.UPDATE)
    @Mongolog(tableName = Mongolog.TableName.BUSINESS,title = "商机跟踪记录",businessType = BusinessType.UPDATE)
    @PutMapping("giveBack/{id}")
    public AjaxResult giveback(@RequestBody Map<String,Object> body){
        return toAjax(businessService.giveBck(Long.valueOf(""+body.get("id"))));
    }

    //捞取
    @Mongolog(tableName = Mongolog.TableName.BUSINESS,title = "商机跟踪记录",businessType = BusinessType.UPDATE)
//    @Log(title = "商机跟踪记录",businessType = BusinessType.UPDATE)
    @PutMapping("resetBusiness/{id}")
    public AjaxResult resetBusiness(@RequestBody Map<String,String> body){
        return toAjax(businessService.reset(Long.valueOf(body.get("id"))));
    }

    //转客户
    @Mongolog(tableName = Mongolog.TableName.BUSINESS,title = "商机跟踪记录",businessType = BusinessType.UPDATE)
//    @Log(title = "商机跟踪记录",businessType = BusinessType.UPDATE)
    @PutMapping("tranfrom")
    public AjaxResult resetBusiness(@RequestBody ContractVo vo){
        return toAjax(businessService.transformCustomer(vo));
    }
}
